import React, { PureComponent, Fragment } from 'react';
import { connect } from 'dva';
import router from 'umi/router';
import { Icon,Button} from 'antd';
import PageHeaderLayout from '../../layouts/PageHeaderLayout';
import styles from '../Pbulic.less';

const tabList = [
  {
    key: "info",
    tab: "点位详情",
  },
  {
    key: "deviceInfo",
    tab: "设备信息",
  }
];

@connect()
export default class EquipmentDetail extends PureComponent {
  constructor(props) {
    super(props);
    
  }


  componentDidMount() {

  }

  componentWillUnmount(){
    const { dispatch } = this.props;
    dispatch({
      type: `point/appendClearState`,
    })
  }

  // 路由切换
  handleTabChange = key => {
    const { match, location, dispatch} = this.props;
    const detailInfoId = match.params.id;
    router.push({ pathname:`/system/point/${detailInfoId}/${key}`,  query: { ...location.query}});
  };

  goBack = () => {
    // this.props.onClose(0);
    const { dispatch, location } = this.props;
    router.push({ pathname:'/system/point/list',  query: { ...location.query} });
  }

  formatterMenu = (data) => {
    return data.reduce((arr, curr) => {
      if(curr.authority){
        if (checkPermissions(curr.authority)) {
          return arr.concat(curr);
        } else {
          return arr.concat([]);
        }
      }else{
        return arr.concat(curr);
      }
    }, []);

  };

  render() {
    const { match, location, children} = this.props;
    const location_arry = location.pathname.split("/");
    const tabDefaultKeys = location_arry[location_arry.length - 1];
    

    return (
      <Fragment>
        <Icon type="close-circle-o"  className={styles.close_icon} onClick={this.goBack}/>
        <PageHeaderLayout
          tabList={this.formatterMenu(tabList)}
          tabActiveKey={tabDefaultKeys}
          onTabChange={this.handleTabChange}
          hiddenBreadcurmb={true}
          title={"点位详情"}
        >
          {children}
        </PageHeaderLayout>
      </Fragment>
    );
  }
}
